function device(){var sUserAgent=navigator.userAgent.toLowerCase();var device={};device.Ipad=sUserAgent.match(/ipad/i)=="ipad";device.Iphone=sUserAgent.match(/iphone os/i)=="iphone os";device.Midp=sUserAgent.match(/midp/i)=="midp";device.Uc7=sUserAgent.match(/rv:1.2.3.4/i)=="rv:1.2.3.4";device.Uc=sUserAgent.match(/ucweb/i)=="ucweb";device.Android=sUserAgent.match(/android/i)=="android";device.CE=sUserAgent.match(/windows ce/i)=="windows ce";device.WM=sUserAgent.match(/windows mobile/i)=="windows mobile";device.phone=device.Iphone||device.Uc7||device.Uc||device.Android||device.CE||device.WM?true:false;device.pad=device.Ipad?true:false;device.mobile=device.pad||device.phone?true:false;return device}
function devRedirect(){
	wl=['/divine'],mhost = 'm.guotuw.com',host = window.location.host;
	var url='',ckn='go_ms',dev = device();
	if(!dev.phone) return;
		url=location.href;
		url=url.toLowerCase();
		for(i=0;i<wl.length;i++){
			if(location.href.indexOf(wl[i])>-1) return
		};
		surl=url;
		surl=surl.replace(host,mhost);
		console.log(surl+'d')
	if(surl) location=surl;
}
//devRedirect();


$(function(){
	$(".search_btn").click(function(){
		var searchKeyword = $.trim($("#searchKey").val());
		if(searchKeyword != ''){
            window.location.href = '/search/?keyword='+searchKeyword;
		}
	});

    $('#searchKey').keydown(function(e){
        if(e.keyCode==13){
            var searchKeyword = $.trim($("#searchKey").val());
            if(searchKeyword != ''){
                window.location.href = '/search/?keyword='+searchKeyword;
            }
        }
    });
});

$(function(){
	var ah =100;
	$(window).scroll(function() {	
		//页面滚动显示隐藏，回到顶部按钮
		var fh = window.screen.height;
	    var dh =document.documentElement.clientHeight;  
	    var ch = $(".bottom").offset().top;
	    var botheight=ch-dh;
		if ($(window).scrollTop() > 145 && $(window).scrollTop() < botheight ) {
			$(".piao").fadeIn(500);
	        $(".piao").css("bottom","50px")
		}
		else {
			if($(window).scrollTop() > botheight){
				var height = $(window).scrollTop()-botheight ;
				$(".piao").css('bottom',50+height+'px');	
			}else{
				$(".piao").fadeOut(500);
				$(".piao").css("bottom","50px");
			}
		}
		
		//页面滚动固定导航
		if ($(window).scrollTop() > 100) {
			$(".nav").css({"position":"fixed","top":"0"})
			$(".nav .nav1 a.icon_logo").css("display","block")
			$(".nav .nav2_list").slideUp();
		} else {
			$(".nav").css("position","static")
			$(".nav .nav1 a.icon_logo").css("display","none")
		}
			
	});

	/*回顶部*/
	$(".piao ul li.icon_returntop").click(function() {
		$('body,html').animate({
			scrollTop: 0
	     }, 500);
	});	

	//窗口水平居中
	$(window).resize(function(){
		login_center();
	});	

	function login_center(){
		var bodyheight=$(window).height()
		var loginheight = $("#layer .login").height()
		var mianbgMt=(bodyheight-loginheight)/2
		$("#layer .login").css("top",mianbgMt);
	}

	$(".imgtxt_list li a").hover(function(){
		$("p",this).stop().animate({bottom:'0'},300);	
	},function(){
		$("p",this).stop().animate({bottom:'-60px'},300);	
	})

//新增内容

  // 宠幸
	$('.chongxing1').on('click',function(){
		$(this).hide();
		$('.chongxing2').show();
		return;

		var login_status = false;//假设登录状态为false
	   if (login_status) {
         $(this).hide();
		 $('.chongxing2').show();
	   }else{
          var html = getLoginBoxHtmls();
          $('body').append(html);
          document.documentElement.style.overflow='hidden';//禁止页面滑动
	   }
	});
	$('.chongxing2').on('click',function(){
		$(this).hide();
		$('.chongxing1').show();
	});

	//签到
	$('.qiandao1').on('click',function(){
		$(this).css('display','none');
		$('.qiandao2').css('display','block');
	});
	$('.qiandao2').on('click',function(){
		$(this).css('display','none');
		$('.qiandao1').css('display','block');
	});

  //登录弹框nav操作
   $(document).on('click','.pnav em',function(){
        $(this).addClass('active').siblings().removeClass('active');
        var index = $(this).index();
        if (index==0) {
            $('.login_info').show();
            $('.register_info').hide();
        }else{
            $('.login_info').hide();
            $('.register_info').show();
        }
     }) 
 //关闭登录注册弹框
   $(document).on('click','.login_closebtn',function(){
        $('.bgbox').hide();
        document.documentElement.style.overflow='auto';//恢复页面滑动
      })

})

function getLoginBoxHtmls(){
	var html ='';
	html+='<div class="bgbox"><div class="loginbox">';
	html+='<div class="pnav"><em class="active">登录</em><em >注册</em><a class="login_closebtn" href="javascripy:void(0)"></a></div>';
    html+='<div class="login_info">';
    html+='<div class="inputtext"><label>手机:</label><div><input type="text"></div></div>';
    html+='<div class="inputtext"><label>密码:</label><div><input type="password"></div></div>';
    html+='<p><input type="checkbox"><label>记住我(两周内免登录)</label><a href="javascripy:void(0)">忘记密码？</a></p>';
    html+='<a class="loginbtn"  href="">登录</a><div class="login_way"><label>其他登录方式:</label>';
    html+='<a href="javascripy:void(0)" class="qq"></a><a href="javascripy:void(0)" class="weixin"></a>';
    html+='<a href="javascripy:void(0)" class="weibo"></a></div></div>';
    html+='<div class="register_info" style="display:none;">';
    html+='<div class="inputtext"><label>绑定手机:</label><div><input type="text"></div></div>';
    html+='<div class="inputtext"><label>短信验证码:</label><div class="yz"><input type="text">';
    html+='<a href="javascripy:void(0)">获取验证码</a></div></div>';
    html+='<div class="inputtext"><label>密码:</label><div><input type="password"></div></div>';
    html+='<a href="javascripy:void(0)" class="registerbtn">保存并登录</a></div></div></div>';  
    return html;      
}	